# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=flatbuffers
pkgver=24.3.25
pkgrel=0
pkgdesc="Memory Efficient Serialization Library"
url="https://flatbuffers.dev/"
# armhf: blocked by bus error in tests
arch="all !armhf"
license="Apache-2.0"
depends_dev="flatc=$pkgver-r$pkgrel"
makedepends="
	cmake
	py3-gpep517
	py3-setuptools
	py3-wheel
	samurai
	"
subpackages="$pkgname-dev flatc py3-$pkgname-pyc py3-$pkgname:py3"
source="flatbuffers-$pkgver.tar.gz::https://github.com/google/flatbuffers/archive/v$pkgver.tar.gz
	locale-headers.patch
	gettemporarypointer-constantness.patch
	"

# secfixes:
#   0:
#     - CVE-2020-35864

build() {
	cmake -B . -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DFLATBUFFERS_BUILD_SHAREDLIB=ON \
		-DFLATBUFFERS_BUILD_FLATLIB=OFF
	cmake --build .

	cd python
	gpep517 build-wheel \
		--wheel-dir ../build/dist \
		--output-fd 3 3>&1 >&2
}

check() {
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install .

	python3 -m installer -d "$pkgdir" \
		build/dist/*.whl
}

flatc() {
	pkgdesc="$pkgdesc (compiler)"

	amove usr/bin
}

py3() {
	pkgdesc="$pkgdesc (python bindings)"
	amove usr/lib/python3*
}

sha512sums="
e2a614f4fc526ce07bfe1e1bc79efd3c87acbdb93aee7b42994d4855abd2593f36b5ca1edb53c7dcd470d5fbe14a3e394bd75dcebb4458cc0aeb33d622a3c662  flatbuffers-24.3.25.tar.gz
a5460ec027f2884f5801e01d3ef7f831be3ecd92fc9586ab33764467e3de79855f87c4b639806ad6884ec8eac41d6d6f6204644c84ddbcea9fba3798943b1e57  locale-headers.patch
6916dd0bd859a8218298d7caeda75e8874f0df9d2160e28451f4e2854d229757f503b6b3e0d541ac3b479a19ecc4af8a4dd6a90af09387d257e066c126a51f24  gettemporarypointer-constantness.patch
"
